package com.itmq;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

public class mailDemo {
    public static void main(String[] args) throws Exception {
        //设置邮件属性
        Properties properties = new Properties();
        properties.setProperty("mail.smtp.host","smtp.qq.com" );
        properties.setProperty("mail.smtp.auth","true" );
        //获取邮件会话对象
        Session session = Session.getInstance(properties);
        //创建消息对象
        MimeMessage message = new MimeMessage(session);
        //设置内容
        message.setFrom(new InternetAddress("2829709690@qq.com"));
        InternetAddress addresses[]={new InternetAddress("2829709690@qq.com"),new InternetAddress("1064266823@qq.com")};
        message.setRecipients(Message.RecipientType.TO,addresses);
       /* message.setFrom(new InternetAddress("itcast106@163.com"));
        message.setRecipient(Message.RecipientType.TO,new InternetAddress("itcast106@163.com"));*/
        //message.setRecipient(Message.RecipientType.TO,new InternetAddress("1473803915@qq.com"));

        message.setSubject("开发邮件");
        message.setText("这是一封开发邮件，请您注意查收！");
        //发送
        Transport transport = session.getTransport("smtp");
        transport.connect("smtp.qq.com", "2829709690@qq.com", "yricnckbdrrpdgfe");
        transport.sendMessage(message,message.getAllRecipients() );
        transport.close();



    }
}
